package com.xtjc03.domain.rest;

import com.xtjc03.domain.entity.Beep;
import com.xtjc03.domain.service.impl.BeepServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value="/api/beep")
public class BeepController {

    @Autowired
    BeepServiceImpl beepService;

    @Value("${server.port}")
    String serverPort;

    @GetMapping("/start")
    public Beep start(){
        return beepService.start();
    }

    @GetMapping("/stop")
    public Beep stop(){
        return beepService.stop();
    }

    @GetMapping("/read")
    public Beep read(){
        return beepService.read();
    }

    @GetMapping("/")
    public Map<String, String> route(){
        Map<String, String> map = new HashMap<>();
        map.put("打开蜂鸣器", "http://127.0.0.1:" + serverPort + "/api/beep/start");
        map.put("关闭蜂鸣器", "http://127.0.0.1:" + serverPort + "/api/beep/stop");
        map.put("读取蜂鸣器状态", "http://127.0.0.1:" + serverPort + "/api/beep/read");
        return map;
    }
}
